package cc.xpcas.raft.network.jvm;

import cc.xpcas.raft.Configuration;
import cc.xpcas.raft.context.Context;
import cc.xpcas.raft.context.Peer;
import cc.xpcas.raft.network.Endpoint;
import cc.xpcas.raft.network.Starter;

/**
 * @author xp
 */
public class JvmStarter extends Starter<JvmAddress> {

    @Override
    protected Class<JvmAddress> getAddressClass() {
        return JvmAddress.class;
    }

    @Override
    protected Endpoint<JvmAddress> initLocal(Configuration configuration, Context context, JvmAddress address) {
        JvmEndpoint endpoint = new JvmEndpoint();
        endpoint.openReceiver(address, configuration.getCodec());
        endpoint.openSender(address, configuration.getCodec());
        return endpoint;
    }

    @Override
    protected Peer initPeer(Context context, int serverId, JvmAddress address) {
        return new Peer(serverId, address, context.getEndpoint());
    }
}
